﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class WeaponFilterPanel : MonoBehaviour
{
    public Toggle m_BigWeapon;
    public Toggle m_MiddleWeapon;
    public Toggle m_SmallWeapon;
    public Toggle m_KWeapon;
    public Toggle m_EWeapon;
    public Toggle m_ENWeapon;
    public Shop m_Shop;
    void Start()
    {
        
    }
    public void CheckFilter(List<CommodityItem> items)
    {
        foreach(var item in items)
        {
            CheckFilter(item);
        }
    }
    public void CheckFilter(CommodityItem item)
    {
        var itemWeapon = item.Item as Weapon;
        if (itemWeapon == null)
            return ;
        item.gameObject.SetActive(CheckFilter(itemWeapon));
    }

    public void CheckFilter(SellItemItem item)
    {
        var itemWeapon = item.Item as Weapon;
        if (itemWeapon == null)
            return;
        item.gameObject.SetActive(CheckFilter(itemWeapon));
    }
    public bool CheckFilter(Weapon weapon)
    {
        bool isPass = false;
        if (weapon.m_Level == Weapon.Level.LEVEL_BIG)
            isPass = m_BigWeapon.isOn;
        if (weapon.m_Level == Weapon.Level.LEVEL_MIDDLE)
            isPass = m_MiddleWeapon.isOn;
        if (weapon.m_Level == Weapon.Level.LEVEL_SMALL)
            isPass = m_SmallWeapon.isOn;

        if (isPass)
        {
            if (weapon.m_DamageType == Weapon.DamageType.TYPE_KINETIC)
                isPass = m_KWeapon.isOn;
            if (weapon.m_DamageType == Weapon.DamageType.TYPE_EXPLOSION)
                isPass = m_EWeapon.isOn;
            if (weapon.m_DamageType == Weapon.DamageType.TYPE_ENERGY)
                isPass = m_ENWeapon.isOn;
        }
        return isPass;
    }
    public void OnFilterChanged()
    {
        m_Shop.Refresh();
    }


    void Update()
    {


#if UNITY_ANDROID
        if (!UtilsUnity.IsOnUI(Input.mousePosition) && (Input.touchCount > 1  || Input.GetMouseButtonDown(0)))
        {
            gameObject.SetActive(false);
        }
#else
        if (Input.GetMouseButtonDown(0) && !EventSystem.current.IsPointerOverGameObject())
        {
            gameObject.SetActive(false);
        }
#endif
    }
}
